import { defineStore } from 'pinia'
import persit from '../persit'
import { getCityApi } from '@/api/home'
const state = () => ({
  // 位置
  location: {}
})

const actions = {
  setLocation(location) {
    this.location = location
  },

  // 请求获取城市
  async getLocationAction({ lat, lng }) {
    // 请求位置
    const location = await getCityApi({
      lat,
      lng
    })
    // 设置位置
    this.setLocation(location)
  }
}
export const useLocationStore = defineStore(
  'location',
  {
    state,
    actions
  },
  persit
)
